/**
 *
 */
define(["durandal/app", "jquery", "knockout", "durandal/composition", 'BMap', 'panel',
        "http", "i18nCommon", "kovholder"],
    function (app, $, ko, composition, baiduMap, panal, http, i18nCommon, kov) {

        function model() {
            var self = this;

            var p, _dom, _human, detailInfo, map, tracePanel, videoPanel, videoReplayPanel;
            var index = 0;
            var timer; //定时器
            var car; //汽车图标
            var label; //信息标签

            var getHumanInfoById = http.getInstance("law/human/getHumanInfoById");

            composition.addBindingHandler("lawinfo-init", {
                init: function (dom) {
                    self.uniqueId = panal.getPanalByElement(dom).uniqueId;
                    p = panal.getPanalByElement(dom);
                    _dom = dom;
                    map = p.param.map;
                    self.humanId = p.param.humanId;
                    initUI();
                    initData();
                    p.settings.onClose = function () {
                        map.clearOverlays();
                    }
                }
            });

            function initUI() {
                p.reload = reload;
                $(_dom).find('.detailinfo').click(function () {
                    panal.getInstance("view/lawdynamic/humaninfo", {
                        title: '人员信息',
                        width: document.body.clientWidth - 320,
                        top: 65,
                        height: document.body.clientHeight - 85,
                        left: 312
                    }, {humanId: self.humanId});

                });

                $(_dom).find('.playtrace').click(function () {
                    if (tracePanel !== undefined) {
                    	tracePanel.close();
                    }
                    tracePanel = panal.getInstance("view/lawdynamic/traceplay", {
                        width: 270,
                        height: 180,
                        bottom: '200px',
                        right: '2px',
                        title: "轨迹播放",
                        modal: false,
                        resizable: false
                    }, {map: map});
                });
                
                $(_dom).find('.replaytrace').click(function () {
                    if (videoReplayPanel !== undefined) {
                    	videoReplayPanel.close();
                    }
                    videoReplayPanel = panal.getInstance("view/lawdynamic/videoreplay", {
                    	width: 500,
                        height: 360,
                        title: "视频回放",
                        modal: false,
                        resizable: false
                    }, {map: map});
                });

                $(_dom).find('.playvideo').click(function () {
                    if (videoPanel !== undefined) {
                    	videoPanel.close();
                    }
                    videoPanel = panal.getInstance("view/lawdynamic/videoplay", {
                        width: 500,
                        height: 360,
                        title: "视频播放",
                        modal: false,
                        resizable: false
                    }, {map: map});
                });

                app.on("lawdynamic:lawinfo").then(function () {
                    p.close();
                });
            }

            function reload(data) {
//			var id = data.id,
//		        index = id.indexOf('_');
//			id = id.substring(index + 1);
//			
//			getPatrolInfoService.ajax({patrolId: id}).then(function(data){
//				renderUI(data);
//			});
                renderUI(data);
            }

            function initData() {
                reload(p.param.data);
                getHumanInfoById.ajax({humanId: self.humanId}).then(function (data) {
                    if (data.human !== null) {
                        $(".name").html(data.human.humanName);
                        $(".unit").html(data.human.unitName);
                    }
                });
            }

            function renderUI(data) {
                detailInfo = data;
                var imgSrc = cywork.global.rootPath + "style/common/images/defaulthuman.png";
//			var law = data.law || {},
//			    human = data.human || {};
                //data.img = data.img || cywork.global.rootPath + "style/common/images/defaulthuman.png";
//			$(_dom).find('.name').text(patrol.patrolName);
//			$(_dom).find('.region').text(data.region);
//			$(_dom).find('.unit').text(human.unitName);
                $(_dom).find('.lawinfo-photo').attr('src', imgSrc);
            }

        }

        return model;
    });